package com.jy.adscm.operation.aftersales.controller;


import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.aftersales.bean.QueryShSpaceParts;
import com.jy.adscm.operation.aftersales.bean.ShSelfRepair;
import com.jy.adscm.operation.aftersales.bean.ShSpaceParts;
import com.jy.adscm.operation.aftersales.service.ShSpacePartsService;
import com.jy.adscm.operation.mscyb.bean.JqbzAssembly;
import com.jy.adscm.operation.mscyb.bean.JqbzPartsassembly;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-08-19
 */
@RestController
@RequestMapping("/adscm/operation/aftersales/shSpaceParts")
public class ShSpacePartsController {

    @Autowired
    ShSpacePartsService shSpacePartsService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;


    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody ShSpaceParts shSpaceParts, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        shSpaceParts.setCreator(token.getUser().getId().toString());
        shSpaceParts.setCreateTime(new Date());
        boolean insert = shSpacePartsService.insertShSpaceParts(shSpaceParts);
        return  new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = shSpacePartsService.deleteShSpaceParts(id);
        return  new SimpleCoreResponse("200","删除成功",insert);
    }
    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryShSpaceParts queryShSpaceParts, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Page<ShSpaceParts> page=new Page<>(queryShSpaceParts.getCurrentPage(),queryShSpaceParts.getPageSize());
        page= shSpacePartsService.selectShSpaceParts(page,queryShSpaceParts);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("selectParts")
    public SimpleCoreResponse selectParts(String code, HttpServletRequest request)throws AdscmSystemException {
        List<JqbzPartsassembly>  jqbzPartsassemblys = shSpacePartsService.selectParts(code);
        return  new SimpleCoreResponse("200","查询成功",jqbzPartsassemblys);
    }
    @RequestMapping("selectSpace")
    public SimpleCoreResponse selectSpace(HttpServletRequest request)throws AdscmSystemException {
        List<ShSpaceParts>  shSpaceParts = shSpacePartsService.selectSpace();
        return  new SimpleCoreResponse("200","查询成功",shSpaceParts);
    }


}

